package com.noble.meether.pay.type;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.noble.meether.R;
import com.noble.library.view.base.BaseDialogFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 支付方式选择弹框
 */
@SuppressLint("ValidFragment")
public class PayTypeDialog extends BaseDialogFragment implements View.OnClickListener {
    private ListView list_view;
    private ArrayAdapter<String> mAdapter;
    private List<String> list = new ArrayList<>();

    private OnDialogItemClick onDialogItemClick;

    public PayTypeDialog(OnDialogItemClick onDialogItemClick) {
        settWindowAnimations(R.style.AnimDownInDownOutOverShoot);
        setGravity(Gravity.BOTTOM);
        setDialogSizeRatio(1, -1);
        setCancelable(true);

        this.onDialogItemClick = onDialogItemClick;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.pay_bottom_dialog);
        initView();
        return getContentView();
    }

    private void initView() {
        getPayItem();
        findViewById(R.id.de_cancel).setOnClickListener(this);
        list_view = (ListView) findViewById(R.id.list_view);
        mAdapter = new ArrayAdapter<>(getContext(), R.layout.pay_dialog_item, R.id.de_type, list);
        list_view.setAdapter(mAdapter);

        list_view.setOnItemClickListener((adapterView, view, i, l) -> {
            if (onDialogItemClick != null) {
                onDialogItemClick.onDialogItemClick(adapterView, view, i, l);
                dismiss();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.de_cancel:
                dismiss();
                break;
        }
    }

    /**
     * 支付弹框弹窗条目内容
     */
    private void getPayItem() {
        list.clear();
        list.add("微信支付");
        list.add("支付宝支付");
    }

    public interface OnDialogItemClick {
        void onDialogItemClick(AdapterView<?> parent, View view, int position, long id);
    }
}